import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Language } from "../../../../../extend/language/Language";
import { ResFileConst } from "../../../resource/ResFileConst";
import { Cache } from "../../../cache/Cache";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { AcupointBuyNimbusPropWindow } from "./AcupointBuyNimbusPropWindow";
import { PulseSharedObject } from "../PulseSharedObject";
import { CheckBoxWin } from "../../common/alertwins/CheckBoxWin";
import { AcupointData } from "./AcupointData";
import { RemainTimeTool } from "../../award/RemainTimeTool";
import { AcupointConfig } from "../../../resource/AcupointConfig";
import { EPrictUnit } from "../../../../../Message/Public/EPrictUnit";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class AcupointSavvyNewUpgrade
    
    export  class AcupointSavvyNewUpgrade /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._tipsLevel = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 279, 395, this, ImagesConst.WindowCenterB);
            ObjCreate.createBg(0, 80, 274, 183, this, ImagesConst.Friend_over);
            ObjCreate.createBg(10, 270, 255, 2, this, ImagesConst.SplitLine);
            addChild(new GImageBitmap("equipment_successRate.png", 65, 85));
            addChild(new GImageBitmap(ImagesConst.LongGreenArrow, 110, 50));
            addChild(new GImageBitmap(ImagesConst.RootBreakArrow, 110, 145));
            var loc1=new GTextFormat("", 16, 65280, null, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this._levelTxt = ObjCreate.createTextField("", 0, 5, 279, 30, this, loc1);
            var loc2=new GTextFormat("", 12, 65280, null, null, null, null, null, flash.text.TextFormatAlign.CENTER, null, null, null, 3);
            this._oldSpeedTxt = ObjCreate.createTextField("", 0, 35, 120, 40, this, loc2);
            var loc3=new GTextFormat("", 12, 16776960, null, null, null, null, null, flash.text.TextFormatAlign.CENTER, null, null, null, 3);
            this._nowSpeedTxt = ObjCreate.createTextField("", 155, 35, 120, 40, this, loc3);
            this._percentTxt = ObjCreate.createTextField("", 100, 35, 80, 20, this, loc2);
            var loc4=new GTextFormat(FontUtil.xingkaiName, 16, 65280);
            this._sucRateTxt = ObjCreate.createTextField("", 145, 88, 150, 30, this, loc4);
            this._nimbusTxt = ObjCreate.createTextField("", 70, 115, 200, 20, this, GlobalStyle.textFormat2);
            this._reduceTimeTxt = ObjCreate.createTextField("", 0, 190, 279, 20, this, loc2);
            this._nowLevelTxt = ObjCreate.createTextField("", 50, 150, 60, 25, this, loc1);
            this._nextLevelTxt = ObjCreate.createTextField("", 160, 150, 60, 25, this, loc1);
            this._countTxt = ObjCreate.createTextField("", 0, 210, 279, 20, this, loc3);
            this._upgradeBtn = ObjCreate.createGButton(Language.getString(30108), 100, 235, 70, 23, this);
            this._upgradeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onUpgradeBtnClickHandler);
            this._tipsBtn = ObjCreate.createGLoadedButton(ResFileConst.ClockBtn, 235, 5, 39, 40, this);
            return;
        }

        /* internal  */onUpgradeBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;
            var gold: int;
            var nimbusNum: int;
            var onClickHandler: Function;
            var str: string;

            var loc1;
            str = null;
            e = arg1;
            gold = Cache.instance.role.money.gold;
            if (gold < this._gold) 
            {
                onClickHandler = (arg1: int): void
                {
                    if (arg1 == Alert.OK) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GotoPay));
                        Alert.resetToDefault();
                    }
                    return;
                }
                Alert.show(Language.getString(30103), null, Alert.OK | Alert.CANCEL, null, onClickHandler);
                return;
            }
            nimbusNum = Cache.instance.role.roleInfo.nimbus;
            if (nimbusNum < this._nimbusNum) 
            {
                if (this._buyNimbusProp == null) 
                {
                    this._buyNimbusProp = new AcupointBuyNimbusPropWindow();
                }
                this._buyNimbusProp.show();
                return;
            }
            if (this._count >= 30 && !PulseSharedObject.isTodayNotTips("UpgradeSavvy")) 
            {
                str = Language.getStringByParam(30259, this._gold);
                Alert.alertWinRenderer = CheckBoxWin;
                Alert.show(str, null, Alert.OK | Alert.CANCEL, null, this.onUpgradeCloseHandler);
            }
            else 
            {
                this.upgradeSavvy();
            }
            return;
        }

        /* internal  */upgradeSavvy(): void
        {
            if (AcupointData.getAcupointCurLevel(this._step, AcupointData.acupointInfo) > 0) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AcupointUpgradeSavvy, this._step));
            }
            else 
            {
                Alert.show(Language.getString(30132), null, Alert.OK, null);
            }
            return;
        }

        /* internal  */onUpgradeCloseHandler(arg1: int, arg2: Boolean): void
        {
            if (arg1 == Alert.OK) 
            {
                this.upgradeSavvy();
            }
            if (arg2) 
            {
                PulseSharedObject.save("UpgradeSavvy", true);
            }
            return;
        }

        /* internal  */getToolTipData(arg1: int, arg2: int, arg3: int): string
        {
            var loc3=0;
            var loc4=null;
            var loc5=0;
            var loc6=NaN;
            var loc1="    ";
            var loc2=AcupointData.getAcupointName(arg1);
            loc1 = (loc1 = (loc1 = (loc1 = loc1 + loc2 + arg2 + Language.getString(30239) + "\n") + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=\'#ffff00\'>" + RemainTimeTool.getRemainTimeBySeconds(arg3) + "</font>\n") + Language.getString(30240) + "\n") + Language.getString(30241) + "\n";
            var loc7="";
            var loc8=0;
            while (loc8 < this._tipsLevel.length) 
            {
                loc3 = this._tipsLevel[loc8];
                loc5 = (loc4 = AcupointConfig.instance.getSavvyInfoByTarget(loc3)).addper / 100;
                loc6 = arg3 * (1 - loc5 / 100);
                if (loc3 < 10) 
                {
                    loc7 = this._tipsLevel[loc8] + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + RemainTimeTool.getRemainTimeBySeconds(loc6) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + loc5 + "%\n";
                }
                else if (loc3 != 10) 
                {
                    if (loc3 > 99) 
                    {
                        loc7 = this._tipsLevel[loc8] + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + RemainTimeTool.getRemainTimeBySeconds(loc6) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + loc5 + "%\n";
                    }
                    else 
                    {
                        loc7 = this._tipsLevel[loc8] + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + RemainTimeTool.getRemainTimeBySeconds(loc6) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + loc5 + "%\n";
                    }
                }
                else 
                {
                    loc7 = this._tipsLevel[loc8] + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + RemainTimeTool.getRemainTimeBySeconds(loc6) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + loc5 + "%\n";
                }
                if (loc3 <= 40) 
                {
                    loc7 = "<font color=\'" + GlobalStyle.color5 + "\'>" + loc7 + "</font>";
                }
                else if (loc3 > 40 && loc3 <= 80) 
                {
                    loc7 = "<font color=\'" + GlobalStyle.color4 + "\'>" + loc7 + "</font>";
                }
                else 
                {
                    loc7 = "<font color=\'" + GlobalStyle.color8 + "\'>" + loc7 + "</font>";
                }
                loc1 = loc1 + loc7;
                ++loc8;
            }
            return loc1;
        }

        public updateConfigInfo(arg1: int): void
        {
            this._step = arg1;
            this._upgradeBtn.enabled = true;
            var loc1=AcupointData.getAcupointCurLevel(arg1, AcupointData.acupointInfo);
            var loc2=AcupointData.getSavvyLevel(arg1);
            this._levelTxt.htmlText = "<font color=\'#ffff00\'>" + Language.getString(30242) + "</font>\t" + loc2 + Language.getString(30243);
            var loc3=loc2 + 1;
            if (loc2 == 100) 
            {
                loc3 = 100;
                this._upgradeBtn.enabled = false;
            }
            var loc4=AcupointConfig.instance.getSavvyInfoByTarget(loc2);
            this._nimbusNum = loc4.nimbus;
            this._nimbusTxt.text = Language.getString(30244) + loc4.nimbus + Language.getString(30092);
            var loc5;
            var loc6=(loc5 = AcupointConfig.instance.getAcupointInfo(loc1, arg1)).time;
            var loc7=loc4.addper;
            var loc8=loc6 * (1 - loc7 / 10000);
            var loc9;
            var loc10=(loc9 = AcupointConfig.instance.getSavvyInfoByTarget(loc3)).addper;
            var loc11=loc6 * (1 - loc10 / 10000);
            this._percentTxt.htmlText = Language.getString(30245) + "<font color=\'#ffff00\'>" + loc7 / 100 + "%</font>";
            this._oldSpeedTxt.text = Language.getString(30143) + "\n" + RemainTimeTool.getRemainTimeBySeconds(loc6);
            this._nowSpeedTxt.text = Language.getString(30144) + "\n" + RemainTimeTool.getRemainTimeBySeconds(loc8);
            var loc12=RemainTimeTool.getRemainTimeBySeconds(loc8 - loc11);
            this._reduceTimeTxt.htmlText = "<font color=\'#b1efff\'>" + Language.getString(30246) + "</font>  " + loc12;
            this._nowLevelTxt.text = loc2 + Language.getString(30243);
            this._nextLevelTxt.text = loc3 + Language.getString(30243);
            this._tipsBtn.toolTipData = this.getToolTipData(arg1, loc1, loc6);
            return;
        }

        public updateSavvyCount(arg1: int, arg2: int): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            this._gold = 0;
            this._count = arg1;
            this._countTxt.htmlText = "";
            if (arg1 < 30) 
            {
                arg1 = 30 - arg1;
                this._countTxt.htmlText = Language.getStringByParam(30247, arg1);
            }
            else 
            {
                if (arg1 > 70) 
                {
                    arg1 = 71;
                }
                loc1 = AcupointConfig.instance.getSavvyUpgradeCostInfo(arg1);
                loc2 = "";
                if (loc1) 
                {
                    this._gold = loc1.cost;
                    if (loc1.unit != EPrictUnit._EPriceUnitGold) 
                    {
                        if (loc1.unit == EPrictUnit._EPriceUnitCoin) 
                        {
                            loc2 = Language.getString(30249);
                        }
                    }
                    else 
                    {
                        loc2 = Language.getString(30248);
                    }
                    this._countTxt.htmlText = Language.getString(30250) + loc2 + "：" + this._gold;
                }
            }
            if (arg2 > 0) 
            {
                loc3 = AcupointData.getSavvyLevel(this._step);
                loc1 = AcupointConfig.instance.getSavvyInfoByTarget(loc3);
                if (loc1 && Cache.instance.vip.isVIP) 
                {
                    this._sucRateTxt.text = loc1.rate + "% + " + Math.ceil(arg2 - loc1.rate) + "%(VIP)";
                }
                else 
                {
                    this._sucRateTxt.text = arg2 + "%";
                }
            }
            else 
            {
                this._sucRateTxt.text = "0%";
            }
            return;
        }

        /* internal */ /* var */_levelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_oldSpeedTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nowSpeedTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_percentTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_reduceTimeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nimbusTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nowLevelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nextLevelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_countTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_sucRateTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_step: int;

        /* internal */ /* var */_gold: int;

        /* internal */ /* var */_nimbusNum: int;

        /* internal */ /* var */_tipsBtn: GLoadedButton;

        /* internal */ /* var */_upgradeBtn: GButton;

        /* internal */ /* var */_tipsLevel: Array<any>;

        /* internal */ /* var */_count: int;

        /* internal */ /* var */_buyNimbusProp: AcupointBuyNimbusPropWindow;
    }
